import React, { createContext, useEffect, useState } from "react";
import { getToken } from "../utils/tools";

export const context = createContext<App.AppProvider>({});

export function AppProvider({ children }: any) {
  const [isLogin, setIsLogin] = useState(getToken() ? true : false);

  const doLogin = () => {
    setIsLogin(true);
  };
  const doLogout = () => {
    setIsLogin(false);
  };

  return (
    <context.Provider value={{ isLogin, doLogin, doLogout }}>
      {children}
    </context.Provider>
  );
}

export default AppProvider;
